{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "31e452d5",
   "metadata": {},
   "source": [
    "-----------------     \n",
    "* 本学习记录人：罗林胜  \n",
    "* 学习时间:2021.11.11    \n",
    "* week06  \n",
    "* [参考文档](https://www.python.org/doc/) \n",
    "*[许老师的博客](https://www.cnblogs.com/xuzhichao)\n",
    "-----------------  "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "86458695",
   "metadata": {},
   "source": [
    "# 本周学习内容\n",
    " \n",
    "## 1.认识[列表]()\n",
    "## 2.列表的取值\n",
    "## 3.列表的一般方法\n",
    "## 4.列表的高级方法"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d156b6f8",
   "metadata": {},
   "source": [
    "### 1.1初始列表\n",
    "\n",
    ">1. 列表的样式：[元素1，元素2，元素3....]  \n",
    ">2.列表的性质：  \n",
    ">>1.列表是有顺序的（Sequence Types 序列类型的数据），第一个元素的位置/索引（index）是0  \n",
    ">>2.列表可以存放不同的类型数据，***但是***一般存放相同类型数据  \n",
    ">>3.列表可以按照序列数据进行取值（index）&切片（slices）  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "1d93c409",
   "metadata": {},
   "outputs": [],
   "source": [
    "username_database=\"Alex;Jack;linsheng;Marry\"\n",
    "username_database_list=[\"Alex;Jack;linsheng;Marry\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "fff47c2c",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Jack\n",
      "Alex;Jack;linsheng;Marry\n"
     ]
    }
   ],
   "source": [
    "# 目标取出每一个账号名称\n",
    "print(username_database[5:9]) #字符串就显得比较麻烦\n",
    "print(username_database_list[0]) # 列表可以按照独立元素进行取值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "bdc5048f",
   "metadata": {},
   "outputs": [],
   "source": [
    "#列表中可以包含不同的 types （int\\float\\str..也可是列表）数据 * 不常这样用\n",
    "different_types_list = [\"Alex\",18,165.5,[\"广东省广州市广州南方学院\",510970]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "46097743",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Alex'"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "different_types_list[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "6e8034eb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "18"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "different_types_list[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "ce20c3d4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "165.5"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "different_types_list[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "a089931d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['广东省广州市广州南方学院', 510970]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "different_types_list[3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "12181d99",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "510970"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "different_types_list[3][1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "ec0663a6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 思考： 取值是否需要知道列表的长度？如果列表只有5个元素，\n",
    "# 取值不能取5以上\n",
    "squares = [1, 4, 9, 16, 25]\n",
    "print(squares[0])\n",
    "#print(squares[10]) # IndexError（索引错误）: list index out of range\n",
    "# 一般 列表的取值需要先知道/清楚列表的长度，取值不要超过其长度范围\n",
    "len(squares) # 取值 不应大于 长度5 位置4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "6feb3bcf",
   "metadata": {},
   "outputs": [],
   "source": [
    "squares = [1, 4, 9, 16, 25]\n",
    "print=(squares[2])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "980b3315",
   "metadata": {},
   "source": [
    "# 2.1切片（slices）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "43671ae5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 9, 16, 25]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "squares"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "bde52a11",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[9, 16]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# （正向取）取9和16\n",
    "squares[2:4]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "dd1310bf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[9, 16]"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# （从右往左取）取9和16.\n",
    "squares[-3:-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "c66d5432",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[9, 16, 25]"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# （从左往右取） 9，16，25：结论：取到末尾或者首位都一律不写最好\n",
    "squares[-3:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "bf5e518d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 9]"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "squares[:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "bb269899",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 9, 25]"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 取1,9？,回顾切片的步长step  [start,stop,step]\n",
    "squares[:5:2]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8b9a5bb2",
   "metadata": {},
   "source": [
    "## 2.2列表取值实践"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "e48befa0",
   "metadata": {},
   "outputs": [],
   "source": [
    "vowels = ['a','e','i','o','u']   # vowels 元音  [\"数字媒体\"]\n",
    "word = \"Milliways\"               # word ：目标文本    文本 1000000个字符\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "a3635381",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i\n",
      "i\n",
      "a\n"
     ]
    }
   ],
   "source": [
    "# 请检查 word 中出现了哪些 vowels 中的元素，并打印出来\n",
    "# 知识点：\n",
    "# 1. for 循环和 if条件判断\n",
    "# 2. in 判断是否存在在列表中 \n",
    "for i in word:\n",
    "    if i in vowels:\n",
    "        print(i)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "b895be4d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a\n",
      "i\n"
     ]
    }
   ],
   "source": [
    "# 请检查vowels中出现的word？\n",
    "for i in vowels:\n",
    "#   print(i)\n",
    "    if i in word:\n",
    "        print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "c8d55531",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入你要查询的文本：hdhsfhasffsjfjajsawtwetyi\n",
      "6 a\n",
      "14 a\n",
      "17 a\n",
      "21 e\n",
      "24 i\n"
     ]
    }
   ],
   "source": [
    "# 扩展案例： 枚举：确定其出现的 位置\n",
    "user_word = input(\"请输入你要查询的文本：\")\n",
    "for i,v in enumerate(user_word):\n",
    "    if v in vowels:\n",
    "        print(i,v)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4ed258c3",
   "metadata": {},
   "source": [
    "#  3.列表的一般方法\n",
    "###  本周作业：课堂练习+如下表所示的表格，总结列表的所有方法"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "84b1e8cd",
   "metadata": {},
   "source": [
    "| 列表的方法      | Description | 一般用在什么场景下|\n",
    "| ----------- | ----------- | ----------- |\n",
    "| append      | 列表的新增：增加元素至列表的末尾      | 新建列表 |\n",
    "| clear   | 列表的清除        | 清空列表元素 |"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "8f1a2a23",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mike', 'Mary', 'Jan', 'Jack']"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"Mike\",\"Mary\",\"Jan\",\"Jack\"]\n",
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bf3f27fd",
   "metadata": {},
   "source": [
    "> 1.append() 列表的新增，增加元素至列表的末尾"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "7637ec1f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function append:\n",
      "\n",
      "append(object, /) method of builtins.list instance\n",
      "    Append object to the end of the list.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.append)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "090b5395",
   "metadata": {},
   "outputs": [],
   "source": [
    "names.append(\"Jan\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "17191b63",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mike', 'Mary', 'Jan', 'Jack', 'Jan']"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0fa0d4d2",
   "metadata": {},
   "source": [
    "> 1.remove() 选择列表的内容/值（values），删除\n",
    ">> *注意：remove()的一般步骤： 1. 先查询 in 2. 再删除"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "f88cbf3f",
   "metadata": {},
   "outputs": [],
   "source": [
    "num_list = [1,4,4,6,5,4,2,8,4,5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "a2da681e",
   "metadata": {},
   "outputs": [],
   "source": [
    "num_list.remove(4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "47292298",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 6, 5, 4, 2, 8, 4, 5]"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "num_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "3bc66efd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function remove:\n",
      "\n",
      "remove(value, /) method of builtins.list instance\n",
      "    Remove first occurrence of value.\n",
      "    \n",
      "    Raises ValueError if the value is not present.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.remove)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "02e23c41",
   "metadata": {},
   "outputs": [],
   "source": [
    "# remove()的一般步骤\n",
    "if \"Mary\" in names: # 先查询，再删除\n",
    "    names.remove(\"Mary\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "8e0709ea",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mike', 'Jan', 'Jack', 'Jan']"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1993a82a",
   "metadata": {},
   "source": [
    "> 3.pop() pop(index=-1, /) 默认的删除 最后一位的值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "ffa8cc59",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function pop:\n",
      "\n",
      "pop(index=-1, /) method of builtins.list instance\n",
      "    Remove and return item at index (default last).\n",
      "    \n",
      "    Raises IndexError if list is empty or index is out of range.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.pop)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "dcb5f904",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Jan'"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names.pop() # 默认删除最后一个"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "3817e190",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mike', 'Jan', 'Jack']"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "c7e50a13",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Jan'"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names.pop(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "cb693388",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mike', 'Jack']"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "c5946486",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 删除实践：\n",
    "stu_id_分数 = [78,88,77,78,90,90,78,88,90,89,95]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "4e64070b",
   "metadata": {},
   "outputs": [],
   "source": [
    "# remove 时 ，可能需要重复运行 才可以按照指定的要求删除所有的值， \n",
    "# 分数在 低于85分 的删除\n",
    "stu_id_分数 = [78,88,77,78,90,90,78,88,90,89,95]\n",
    "for j in stu_id_分数:\n",
    "    if j<85: #判断是否还有值小于85 \n",
    "        for i in stu_id_分数:\n",
    "            if i < 85:\n",
    "                stu_id_分数.remove(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "839ff02b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[88, 90, 90, 88, 90, 89, 95]"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stu_id_分数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "a5c6374a",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 删除实践: 需要执行两次 即可删干净\n",
    "stu_id_分数 = [78,88,77,78,90,90,78,88,90,89,95,77,78,98,77,82]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "48dba4f0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "当前的列表： [78, 88, 77, 78, 90, 90, 78, 88, 90, 89, 95, 77, 78, 98, 77, 82]\n",
      "循环遍历结果： 0 78\n",
      "当值小于85时 要删除的值： 78\n",
      "当前的列表： [88, 77, 78, 90, 90, 78, 88, 90, 89, 95, 77, 78, 98, 77, 82]\n",
      "循环遍历结果： 1 77\n",
      "当值小于85时 要删除的值： 77\n",
      "当前的列表： [88, 78, 90, 90, 78, 88, 90, 89, 95, 77, 78, 98, 77, 82]\n",
      "循环遍历结果： 2 90\n",
      "当前的列表： [88, 78, 90, 90, 78, 88, 90, 89, 95, 77, 78, 98, 77, 82]\n",
      "循环遍历结果： 3 90\n",
      "当前的列表： [88, 78, 90, 90, 78, 88, 90, 89, 95, 77, 78, 98, 77, 82]\n",
      "循环遍历结果： 4 78\n",
      "当值小于85时 要删除的值： 78\n",
      "当前的列表： [88, 78, 90, 90, 88, 90, 89, 95, 77, 78, 98, 77, 82]\n",
      "循环遍历结果： 5 90\n",
      "当前的列表： [88, 78, 90, 90, 88, 90, 89, 95, 77, 78, 98, 77, 82]\n",
      "循环遍历结果： 6 89\n",
      "当前的列表： [88, 78, 90, 90, 88, 90, 89, 95, 77, 78, 98, 77, 82]\n",
      "循环遍历结果： 7 95\n",
      "当前的列表： [88, 78, 90, 90, 88, 90, 89, 95, 77, 78, 98, 77, 82]\n",
      "循环遍历结果： 8 77\n",
      "当值小于85时 要删除的值： 77\n",
      "当前的列表： [88, 78, 90, 90, 88, 90, 89, 95, 78, 98, 77, 82]\n",
      "循环遍历结果： 9 98\n",
      "当前的列表： [88, 78, 90, 90, 88, 90, 89, 95, 78, 98, 77, 82]\n",
      "循环遍历结果： 10 77\n",
      "当值小于85时 要删除的值： 77\n",
      "当前的列表： [88, 78, 90, 90, 88, 90, 89, 95, 78, 98, 82]\n",
      "循环遍历结果： 0 88\n",
      "当前的列表： [88, 78, 90, 90, 88, 90, 89, 95, 78, 98, 82]\n",
      "循环遍历结果： 1 78\n",
      "当值小于85时 要删除的值： 78\n",
      "当前的列表： [88, 90, 90, 88, 90, 89, 95, 78, 98, 82]\n",
      "循环遍历结果： 2 90\n",
      "当前的列表： [88, 90, 90, 88, 90, 89, 95, 78, 98, 82]\n",
      "循环遍历结果： 3 88\n",
      "当前的列表： [88, 90, 90, 88, 90, 89, 95, 78, 98, 82]\n",
      "循环遍历结果： 4 90\n",
      "当前的列表： [88, 90, 90, 88, 90, 89, 95, 78, 98, 82]\n",
      "循环遍历结果： 5 89\n",
      "当前的列表： [88, 90, 90, 88, 90, 89, 95, 78, 98, 82]\n",
      "循环遍历结果： 6 95\n",
      "当前的列表： [88, 90, 90, 88, 90, 89, 95, 78, 98, 82]\n",
      "循环遍历结果： 7 78\n",
      "当值小于85时 要删除的值： 78\n",
      "当前的列表： [88, 90, 90, 88, 90, 89, 95, 98, 82]\n",
      "循环遍历结果： 8 82\n",
      "当值小于85时 要删除的值： 82\n"
     ]
    }
   ],
   "source": [
    "for j in stu_id_分数:\n",
    "    if j<85:\n",
    "        for i,v in enumerate(stu_id_分数):\n",
    "            print(\"当前的列表：\",stu_id_分数)\n",
    "            print(\"循环遍历结果：\",i,v)\n",
    "            if v < 85:\n",
    "                print(\"当值小于85时 要删除的值：\",stu_id_分数.pop(i))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "93e1686c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[88, 90, 90, 88, 90, 89, 95, 98]"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stu_id_分数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "76de7de0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "3\n",
      "5\n",
      "7\n",
      "9\n"
     ]
    }
   ],
   "source": [
    "stu_id=[\"210010001\",\"210010002\",\"210010003\",\"210010004\",\"210010005\",\"210010006\",\"210010007\",\"210010008\",\"210010009\"]\n",
    "odds=[1,3,5,7,9]\n",
    "for i in stu_id:\n",
    "    print(i[-1])\n",
    "    if int(i[-1]) in odds:\n",
    "        stu_id.remove(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "8a370bcc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['210010002', '210010004', '210010006', '210010008']"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stu_id"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b6f18128",
   "metadata": {},
   "source": [
    "#  作业\n",
    "> 1.课堂练习 *2.如下表所示的表格，总结方法\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3b6e2fc5",
   "metadata": {},
   "source": [
    "| 列表的方法      | Description | 一般用在什么场景下|\n",
    "| ----------- | ----------- | ----------- |\n",
    "| append      | 列表的新增：增加元素至列表的末尾      | 新建列表 |\n",
    "|remove|列表的减少(删除掉列表中的值，需元素的全称)|在列表中减少一个元素|\n",
    "|pop|列表的减少(删除掉列表中的值，需元素的索引值）|在列表中减少一个元素|\n",
    "| clear   | 列表的清除        | 清空列表元素 |\n",
    "|count|查询列表里有几个你想要的元素 count(元素)|查询列表中想要元素的数量|\n",
    "|reverse|将列表中的元素进行倒序排列 reverse()|想要把列表进行反转|\n",
    "|index|index(想要看的元素)|想知道一个元素在列表中的索引值是哪个|\n",
    "|insert|insert(要插入的位置，插入的元素)|把一个想要插入的元素插入到索引值的前面|"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "e16e24fb",
   "metadata": {},
   "outputs": [],
   "source": [
    "#clear\n",
    "good=[11,56,18,72,89,15,75]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "2d8400ab",
   "metadata": {},
   "outputs": [],
   "source": [
    "good.clear()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "0b429d2d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "good"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "e8c04f17",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#count\n",
    "good.count(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "68cf94ba",
   "metadata": {},
   "outputs": [],
   "source": [
    "waa=[55,89,45,66,78,22]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "2f3d3a02",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "waa.count(22)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "a69fd8c0",
   "metadata": {},
   "outputs": [],
   "source": [
    "#reverse\n",
    "waa.reverse()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "942809ce",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[22, 78, 66, 45, 89, 55]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "waa"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "f1579b8d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#index\n",
    "waa.index(66)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "7d9d2558",
   "metadata": {},
   "outputs": [],
   "source": [
    "#insert\n",
    "waa.insert(4,77)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "55b2720d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[22, 78, 66, 45, 77, 89, 55]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "waa"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "033b928e",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
